package com.zfy.cmsservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zfy.cmsservice.entity.Semesters;
import com.zfy.cmsservice.mapper.SemestersMapper;
import com.zfy.cmsservice.service.SemestersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zfy.commonutils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 学期表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2023-12-02
 */
@Service
public class SemestersServiceImpl extends ServiceImpl<SemestersMapper, Semesters> implements SemestersService {
    @Autowired
    private SemestersMapper semestersMapper;
    @Override
    public R pageSemesters(long page, long size, String name) {
        // 创建分页page对象
        Page<Semesters> semestersPage = new Page<>(page, size);
        // 构建条件Wrapper
        QueryWrapper<Semesters> wrapper = new QueryWrapper<>();
        if(name!= null) {
            wrapper.like("name",name);
        }
        // 排序
        wrapper.orderByDesc("gmt_modified");
        // 调用方法实现带分页条件查询
        this.page(semestersPage, wrapper);
        long total = semestersPage.getTotal(); // 总记录数
        List<Semesters> records = semestersPage.getRecords();// 数据 list 集合
        return R.ok().data("total", total).data("content", records);
    }

    @Override
    public List<Semesters> findAllSemesters() {
        return semestersMapper.findAllSemesters();
    }
}
